define(
	[
		'require',
		'broada/ui/dialog',
		'broada/base/text!../tpls/business_config_threshold.hbs',
		'apm/ui/myself_select/select'
	],
	function(require) {
		var Dialog = require('broada/ui/dialog');
		var tpl = require('broada/base/text!../tpls/business_config_threshold.hbs');

		var thresholdTypesCache;
		var BusinessConfigThresholdComponent = Ember.Component.extend({
			select: require('apm/ui/myself_select/select'),

			layout: Ember.HTMLBars.compile(tpl),

			Dialog: Dialog,

			dialogId: "businessConfigThresholdsDialog",

			dialogButtons: {
				ok: {
					text: "确定",
					"class": "btn btn-primary",
					click: function() {
						var view = this.get("context"),
							targetResource = view.get("targetResource"),
							algorithm = view.get("algorithm");

						if (!algorithm) {
							if (targetResource) {
								view.set("thresholdForm.targetId", targetResource.targetId);
							}
							if (overviewOrCenterSwitch == "business") {
								if (!view.validateTradingForm()) {
									return;
								}
							} else {
								if (!view.validateThresholdForm()) {
									return;
								}
							};

							var resources = view.get("resources");
							var promise;
							if (targetResource) {
								promise = view.updateThreshold();
							} else {
								promise = view.addThreshold();
							}
							promise.then(function(threshold) {
								view.closeDialog();
								view.send("saved", threshold);
							});
							view.send("ok");
						} else {
							if (targetResource) {
								view.set("thresholdForm.targetId", targetResource.targetId);
							}
							var promise;
							if (targetResource) {
								promise = view.updateThreshold();
							} else {
								promise = view.addThreshold();
							}
							promise.then(function(threshold) {
								view.closeDialog();
								view.send("saved", threshold);
							});
							view.send("ok");
						}
					}
				},
				clear: {
					text: "清空",
					"class": "btn",
					click: function() {
						var view = this.get("context"),
							algorithm = view.get("algorithm");

						if (!algorithm) {
							if (view.get("thresholdSwitch")) {
								view.clearTradingParam();
								view.send("clear");
							} else {
								view.clearThresholdParam();
								view.send("clear");
							}
						} else {

						}
					}
				},
				cancel: {
					text: "取消",
					"class": "btn",
					click: function() {
						var view = this.get("context"),
							algorithm = view.get("algorithm");

						if (!algorithm) {
							this.get("context").send("cancel");
							this.closeDialog();
						} else {
							this.closeDialog();
						}
					}
				}
			},

			didInsertElement: function() {
				var ctrl = this;

				if (this.get("isShowSystemAndBusiness")) {
					$(".threshold-label-tabs li").on("click", function() {
						$(this).addClass("active").siblings().removeClass('active');
						var text = $(this).text();

						if (text == "交易量阈值参数") {
							overviewOrCenterSwitch = 'business';
							ctrl.set("thresholdSwitch", true);
						} else {
							overviewOrCenterSwitch = 'system';
							ctrl.set("thresholdSwitch", false);
						}
					});
				} else {
					if (this.get("isShowSystem")) {
						$(".threshold-label-tabs li").addClass("active");
						ctrl.set("thresholdSwitch", false);
					} else {
						$(".threshold-label-tabs li").addClass("active");
						ctrl.set("thresholdSwitch", true);
					}
				}
			},

			willDestroyElement: function() {},

			openDialog: function() {
				if (!this.get("targetResource")) {
					this.requireResources();
				}
				this.set("thresholdsFormTip", null);
				Broada.getView(this.dialogId).openDialog();
				return this;
			},

			closeDialog: function() {
				Broada.getView(this.dialogId).closeDialog();
				return this;
			},

			thresholdTypes: Ember.computed(function(key, value) {
				if (arguments.length == 1) {
					if (thresholdTypesCache) {
						return thresholdTypesCache;
					} else {
						this.requireThresholdTypes();
					}
					return Ember.A();
				} else {
					return value;
				}
			}),

			thresholdForm: Ember.computed(function(key, value) {
				if (arguments.length == 2) {
					if (value) {
						return this._translateThresholdToLocal(value);
					}
				} else {
					return this._translateThresholdToLocal(value);
				}
			}),

			tradingForm: Ember.computed(function(key, value) {
				if (arguments.length == 2) {
					if (value) {
						return this._translateTradingToLocal(value);
					}
				} else {
					return this._translateTradingToLocal(value);
				}
			}),

			thresholdTypesChange: Ember.observer("thresholdTypes", function() {
				var me = this,
					thresholdTypes = this.get("thresholdTypes"),
					thresholdForm = this.get("thresholdForm"),
					tradingForm = this.get("tradingForm");
				if (thresholdTypes && thresholdTypes[0] && thresholdTypes[0].code) {
					if (thresholdForm && !thresholdForm.thresholdType) {
						me.set("thresholdForm.thresholdType", thresholdTypes[0].code);
					}
					if (tradingForm && !tradingForm.thresholdType) {
						me.set("tradingForm.thresholdType", thresholdTypes[0].code);
					}
				}
			}),
			thresholdFormThresholdTypesChange: Ember.observer("thresholdForm.thresholdType", function() {
				var me = this;
				if (me.get("thresholdForm.thresholdType") == "algorithm") {
					me.set("thresholdsFormTip", "");
					me.set("algorithm", true);
				} else {
					me.set("algorithm", false);
				};
			}),

			resourcesChange: Ember.observer("resources", function() {
				var me = this,
					resources = this.get("resources"),
					thresholdForm = this.get("thresholdForm"),
					tradingForm = this.get("tradingForm");
				if (resources && resources[0] && resources[0].id) {
					if (thresholdForm && !this.get("targetResource")) {
						me.set("thresholdForm.targetId", resources[0].id);
						me.set("tradingForm.targetId", resources[0].id);
					}
				}
			}),

			thresholdFormChange: Ember.observer("thresholdForm", "tradingForm", function() {
				this.thresholdTypesChange();
				this.resourcesChange();
			}),

			clearThresholdParam: function() {
				var set = Ember.set;
				this.get("thresholdForm.thresholdParam").forEach(function(tsParam) {
					set(tsParam, "times", "");
					set(tsParam, "level_50", "");
					set(tsParam, "level_20", "");
					set(tsParam, "level_10", "");
				});
			},
			clearTradingParam: function() {
				var set = Ember.set;
				this.get("tradingForm.thresholdParam").forEach(function(tsParam) {
					set(tsParam, "times", "");
					set(tsParam, "level_50", "");
					set(tsParam, "level_20", "");
					set(tsParam, "level_10", "");
				});
			},

			newThresholdForm: function() {
				this.set("thresholdForm", this._createThresholdForm());
				this.set("tradingForm", this._createTradingForm());
				return this;
			},

			_createThresholdForm: function() {
				return {
					targetId: null,
					thresholdType: null,
					thresholdParam: Ember.A([{
						indicator: "rpm",
						operator: ">",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "lrpm",
						operator: "<",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "rtt",
						operator: ">",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "success",
						operator: "<",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "error",
						operator: ">",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}])
				};
			},

			_createTradingForm: function() {
				return {
					targetId: null,
					thresholdType: null,
					thresholdParam: Ember.A([{
						indicator: "brpm",
						operator: ">",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "blrpm",
						operator: "<",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "brtt",
						operator: ">",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "bsuccess",
						operator: "<",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "berror",
						operator: ">",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}, {
						indicator: "bapdex",
						operator: "<",
						times: "",
						level: {
							"50": "",
							"20": "",
							"10": "",
						}
					}])
				};
			},

			requireThresholdTypes: function() {
				var me = this,
					store = this.container.lookup("store:apm");

				return store.ajax("GET", "configs/alertThreshold")
					.then(function(response) {
						var types = Ember.A(response.result || []);
						me.set("thresholdTypes", types);
						thresholdTypesCache = types;
					});
			},

			requireResources: function() {
				var me = this,
					store = this.container.lookup("store:apm"),
					appId = this.get("appId");

				if (!appId) {
					return;
				}

				if (overviewOrCenterSwitch == "business") {
					var panelId = "business";
				} else {
					var panelId = "system"
				}

				return store.ajax("GET", "applications/" + appId + "/baseResource/" + panelId)
					.then(function(response) {
						var thresholds = [];
						Ember.A(response.result).forEach(function(node) {
							if (node.id.indexOf("-") != -1) {
								thresholds.push(node);
							}
						});
						if (overviewOrCenterSwitch == "business") {
							me.set("resources", Ember.A(response.result));
						} else {
							me.set("resources", Ember.A(thresholds));
						}
					});
			},

			requireThreshold: function(targetId) {
				var me = this,
					store = this.container.lookup("store:apm"),
					appId = this.get("appId"),
					alwaysBusiness = this.get("alwaysBusinesss");;

				if (!appId || !targetId) {
					return;
				}
				me.set("thresholdTypeName",'阈值告警');

				return store.ajax("GET", "alarms/" + appId + '/' + targetId + '/' + (alwaysBusiness ? "business" : overviewOrCenterSwitch) + "/thresholds")
					.then(function(response) {
						if (!response.result) {
							me.set("thresholdForm", {});
							me.set("tradingForm", {});
						}

						if (!response.result) {
							response.result = {};
						}

						if(response.result){
							me.set("thresholdTypeName",response.result.thresholdTypeName);
						}else{
							me.set("thresholdTypeName","阈值告警");
						}

						me.set("thresholdForm", response.result);
						me.set("tradingForm", response.result);
					}, function() {
						me.set("thresholdForm", {});
						me.set("tradingForm", {});
					});
			},

			updateThreshold: function() {
				var me = this,
					thresholdForm = this.get("thresholdForm"),
					tradingForm = this.get("tradingForm"),
					appId = this.get("appId"),
					store = this.container.lookup("store:apm"),
					algorithm = this.get("algorithm"),
					targetResource = this.get("targetResource"),
					alwaysBusiness = this.get("alwaysBusiness");

				var panelId = overviewOrCenterSwitch == "business" ? "business" : "system";

				var threshold = this._translateThresholdToRemote(thresholdForm);

				var trading = this._translateTradingToRemote(tradingForm),

					targetResource = this.get("targetResource");

				trading.targetId = threshold.targetId;

				if (this.get("alwaysBusiness")) {

					threshold = trading;

				} else if (this.get("isShowSystemAndBusiness")) {
					panelId = "default";

					//数据拼接在一起
					var thresholdAndtrading = trading.thresholdParam.concat(threshold.thresholdParam);

					threshold.thresholdParam = thresholdAndtrading;
				} else {
					threshold = overviewOrCenterSwitch == "business" ? trading : threshold;
				}

				if (this.get("isShowSystemAndBusiness")) {
					panelId = "default";
				} else if (this.get("alwaysBusiness")) {
					panelId = "business";
				}

				if (algorithm) {
					threshold = {
						"targetId": trading.targetId,
						"thresholdType": "algorithm",
						"status": "on",
						"thresholdParam": []
					}
				} else {
					threshold.thresholdType = "threshold";
				}

				return store.ajax("PUT", "alarms/" + appId + "/thresholds/" + (alwaysBusiness ? "business" : overviewOrCenterSwitch), threshold)
					.then(function() {
						if (threshold.thresholdType == "algorithm") {
							threshold.thresholdParam[0] = {
								"indexName": "基线告警"
							};
						};
						threshold.thresholdParam.forEach(function(node) {

							if (node.indicator == "brpm") {
								node.indexName = "交易量上限"
							};

						});
						return threshold;;
					});
			},

			addThreshold: function() {
				var me = this,
					thresholdForm = this.get("thresholdForm"),
					tradingForm = this.get("tradingForm"),
					appId = this.get("appId"),
					store = this.container.lookup("store:apm"),
					algorithm = this.get("algorithm"),
					targetResource = this.get("targetResource"),
					alwaysBusiness = this.get("alwaysBusinesss");

				var threshold = this._translateThresholdToRemote(thresholdForm);

				var trading = this._translateTradingToRemote(tradingForm);

				trading.targetId = threshold.targetId;

				if (this.get("alwaysBusiness")) {

					threshold = trading;

				} else if (this.get("isShowSystemAndBusiness")) {
					panelId = "default";

					//数据拼接在一起
					var thresholdAndtrading = trading.thresholdParam.concat(threshold.thresholdParam);

					threshold.thresholdParam = thresholdAndtrading;
				} else {
					threshold = overviewOrCenterSwitch == "business" ? trading : threshold;
				}

				if (this.get("isShowSystemAndBusiness")) {
					panelId = "default";
				} else if (this.get("alwaysBusiness")) {
					panelId = "business";
				}

				if (algorithm) {
					threshold = {
						"targetId": trading.targetId,
						"thresholdType": "algorithm",
						"status": "on",
						"thresholdParam": [],
						"panelId": overviewOrCenterSwitch
					}
				} else {
					threshold.thresholdType = "threshold";
				}

				return store.ajax("POST", "alarms/" + appId + "/" + (alwaysBusiness ? "business" : overviewOrCenterSwitch) + "/thresholds", threshold)
					.then(function() {
						if (threshold.thresholdType == "algorithm") {
							threshold.thresholdParam[0] = {
								"indexName": "基线告警"
							};
						};
						var reource = me.get("resources").findBy("id", thresholdForm.targetId);
						threshold.targetName = reource.name;
						threshold.thresholdParam.forEach(function(node) {
							if (node.indicator == "brpm") {
								node.indexName = "交易量上限"
							};
						});
						return threshold;;
					});
			},

			validateThresholdForm: function() {
				var form = this.get("thresholdForm"),
					isBlank = Ember.isBlank;

				var reg = /^\+?[1-9][0-9]*$/;
				var reg2;
				var tip;
				//找出需要校验的指标
				var thresholdParams = form.thresholdParam.filter(function(tsParam, i) {
					if (isBlank(tsParam.level_50) &&
						isBlank(tsParam.level_20) &&
						isBlank(tsParam.level_10) &&
						isBlank(tsParam.times)) {
						return false;
					} else {
						return true;
					}
				});

				var operatorNameMap = {
					rpm: "高于",
					lrpm: "低于",
					rtt: "高于",
					apdex: "低于",
					success: "低于",
					error: "大于"
				};
				for (var i = 0, l = thresholdParams.length; i < l; i++) {
					var tsParam = thresholdParams[i],
						indicator = tsParam.indicator,
						indicatorName = tsParam.indicatorName,
						level_50 = tsParam.level_50,
						level_20 = tsParam.level_20,
						level_10 = tsParam.level_10;


					if (indicator == "apdex") {
						reg2 = /^[01]$|^0.\d/;
						tip = "必须为0 ~ 1之间的数！";
					} else if (indicator == "success") {
						reg2 = /^(100|\d{1,2})$/;
						tip = "必须为0 ~ 100之间的数！";
					} else {
						reg2 = /^[\d]+$/;
						tip = "必须为整数！";
					}
					if (!isBlank(level_50) && !reg2.test(level_50)) {
						this.set("thresholdsFormTip", indicatorName + "严重阈值" + tip);
						return false;
					}
					if (!isBlank(level_20) && !reg2.test(level_20)) {
						this.set("thresholdsFormTip", indicatorName + "警告阈值" + tip);
						return false;
					}
					if (!isBlank(level_10) && !reg2.test(level_10)) {
						this.set("thresholdsFormTip", indicatorName + "提醒阈值" + tip);
						return false;
					}

					if (!isBlank(level_50)) {
						if (!isBlank(level_20)) {
							if (!eval("parseFloat(level_50)" + tsParam.operator + "parseFloat(level_20)")) {
								this.set("thresholdsFormTip", indicatorName + "严重阈值必须" + operatorNameMap[indicator] + "警告阈值！");
								return false;
							}
						}
						if (!isBlank(level_10)) {
							if (!eval("parseFloat(level_50)" + tsParam.operator + "parseFloat(level_10)")) {
								this.set("thresholdsFormTip", indicatorName + "严重阈值必须" + operatorNameMap[indicator] + "提醒阈值！");
								return false;
							}
						}
					}
					if (!isBlank(level_20)) {
						if (!isBlank(level_10)) {
							if (!eval("parseFloat(level_20)" + tsParam.operator + "parseFloat(level_10)")) {
								this.set("thresholdsFormTip", indicatorName + "警告阈值必须" + operatorNameMap[indicator] + "提醒阈值！");
								return false;
							}
						}
					}
					if (!reg.test(tsParam.times)) {
						this.set("thresholdsFormTip", indicatorName + "持续时间必须为整数！");
						return false;
					}
				}

				if (this.get("isConfig")) {
					if (!level_50 && !level_20 && !level_10) {
						this.set("thresholdsFormTip", "严重阈值,警告阈值,提醒阈值不能都为空");
						return false;
					}
				}

				this.set("thresholdsFormTip", null);
				return true;
			},

			validateTradingForm: function() {
				var form = this.get("tradingForm"),
					isBlank = Ember.isBlank;

				if (!form.thresholdType) {
					this.set("thresholdsFormTip", "请选择阈值类型!");
					return false;
				}

				var reg = /^\+?[1-9][0-9]*$/;
				var reg2;
				var tip;
				//找出需要校验的指标
				var thresholdParams = form.thresholdParam.filter(function(tsParam, i) {
					if (isBlank(tsParam.level_50) &&
						isBlank(tsParam.level_20) &&
						isBlank(tsParam.level_10) &&
						isBlank(tsParam.times)) {
						return false;
					} else {
						return true;
					}
				});

				var operatorNameMap = {
					brpm: "高于",
					blrpm: "低于",
					brtt: "高于",
					bapdex: "低于",
					bsuccess: "低于",
					berror: "大于"
				};

				for (var i = 0, l = thresholdParams.length; i < l; i++) {
					var tsParam = thresholdParams[i],
						indicator = tsParam.indicator,
						indicatorName = tsParam.indicatorName,
						level_50 = tsParam.level_50,
						level_20 = tsParam.level_20,
						level_10 = tsParam.level_10;

					if (indicator == "bapdex") {
						reg2 = /^[01]$|^0.\d/;
						tip = "必须为0 ~ 1之间的数！";
					} else if (indicator == "bsuccess") {
						reg2 = /^(100|\d{1,2})$/;
						tip = "必须为0 ~ 100之间的数！";
					} else {
						reg2 = /^[\d]+$/;
						tip = "必须为整数！";
					}
					if (!isBlank(level_50) && !reg2.test(level_50)) {
						this.set("thresholdsFormTip", indicatorName + "严重阈值" + tip);
						return false;
					}
					if (!isBlank(level_20) && !reg2.test(level_20)) {
						this.set("thresholdsFormTip", indicatorName + "警告阈值" + tip);
						return false;
					}
					if (!isBlank(level_10) && !reg2.test(level_10)) {
						this.set("thresholdsFormTip", indicatorName + "提醒阈值" + tip);
						return false;
					}

					if (!isBlank(level_50)) {
						if (!isBlank(level_20)) {
							if (!eval("parseFloat(level_50)" + tsParam.operator + "parseFloat(level_20)")) {
								this.set("thresholdsFormTip", indicatorName + "严重阈值必须" + operatorNameMap[indicator] + "警告阈值！");
								return false;
							}
						}
						if (!isBlank(level_10)) {
							if (!eval("parseFloat(level_50)" + tsParam.operator + "parseFloat(level_10)")) {
								this.set("thresholdsFormTip", indicatorName + "严重阈值必须" + operatorNameMap[indicator] + "提醒阈值！");
								return false;
							}
						}
					}
					if (!isBlank(level_20)) {
						if (!isBlank(level_10)) {
							if (!eval("parseFloat(level_20)" + tsParam.operator + "parseFloat(level_10)")) {
								this.set("thresholdsFormTip", indicatorName + "警告阈值必须" + operatorNameMap[indicator] + "提醒阈值！");
								return false;
							}
						}
					}
					if (!reg.test(tsParam.times)) {
						this.set("thresholdsFormTip", indicatorName + "持续时间必须为整数！");
						return false;
					}

				}
				if (this.get("isConfig")) {
					if (!level_50 && !level_20 && !level_10) {
						this.set("thresholdsFormTip", indicatorName + "严重阈值,警告阈值,提醒阈值不能都为空");
						return false;
					}
				}

				this.set("thresholdsFormTip", null);
				return true;
			},

			_translateThresholdToLocal: function(threshold) {
				var _threshold = this._createThresholdForm();

				_threshold.targetId = threshold ? threshold.targetId : null;
				_threshold.thresholdType = threshold ? threshold.thresholdType : null;

				var indicatorNameMap = {
					rpm: "吞吐量",
					lrpm: "吞吐量",
					rtt: "响应时间",
					success: "成功率",
					error: "错误数"
				};
				var unitMap = {
					rpm: "rpm",
					lrpm: "rpm",
					rtt: "ms",
					success: "%",
					error: ""
				};
				var operatorNameMap = {
					rpm: "(高于)",
					lrpm: "(低于)",
					rtt: "(高于)",
					success: "(低于)",
					error: "(大于)"
				};

				var thresholdMap = {};
				if (threshold) {
					Ember.A(threshold.thresholdParam).forEach(function(tsParam) {
						thresholdMap[tsParam.indicator] = tsParam;
					});
				}

				Ember.A(_threshold.thresholdParam).forEach(function(_tsParam) {
					var tsParam = thresholdMap[_tsParam.indicator];
					if (tsParam) {
						_tsParam.times = tsParam.times;
						Ember.merge(_tsParam.level, tsParam.level);
					}

					_tsParam.indicatorName = indicatorNameMap[_tsParam.indicator] || "";
					_tsParam.level_50 = _tsParam.level["50"];
					_tsParam.level_20 = _tsParam.level["20"];
					_tsParam.level_10 = _tsParam.level["10"];
					_tsParam.unit = unitMap[_tsParam.indicator] || "";
					_tsParam.operatorName = operatorNameMap[_tsParam.indicator] || "";
				});

				return _threshold;
			},

			_translateTradingToLocal: function(threshold) {
				var _threshold = this._createTradingForm();
				_threshold.targetId = threshold ? threshold.targetId : null;
				_threshold.thresholdType = threshold ? threshold.thresholdType : null;

				var indicatorNameMap = {
					brpm: "交易量",
					blrpm: "交易量",
					brtt: "响应时间",
					bapdex: "Apdex",
					bsuccess: "成功率",
					berror: "错误数"
				};
				var unitMap = {
					brpm: "rpm",
					blrpm: "rpm",
					brtt: "ms",
					bapdex: "",
					bsuccess: "%",
					berror: ""
				};
				var operatorNameMap = {
					brpm: "(高于)",
					blrpm: "(低于)",
					brtt: "(高于)",
					bapdex: "(低于)",
					bsuccess: "(低于)",
					berror: "(大于)"
				};

				var thresholdMap = {};
				if (threshold) {
					Ember.A(threshold.thresholdParam).forEach(function(tsParam) {
						thresholdMap[tsParam.indicator] = tsParam;
					});
				}


				Ember.A(_threshold.thresholdParam).forEach(function(_tsParam) {
					var tsParam = thresholdMap[_tsParam.indicator];
					if (tsParam) {
						_tsParam.times = tsParam.times;
						Ember.merge(_tsParam.level, tsParam.level);
					}

					_tsParam.indicatorName = indicatorNameMap[_tsParam.indicator] || "";

					_tsParam.level_50 = _tsParam.level["50"];
					_tsParam.level_20 = _tsParam.level["20"];
					_tsParam.level_10 = _tsParam.level["10"];
					_tsParam.unit = unitMap[_tsParam.indicator] || "";
					_tsParam.operatorName = operatorNameMap[_tsParam.indicator] || "";
				});
				return _threshold;
			},

			_translateThresholdToRemote: function(threshold) {
				var isBlank = Ember.isBlank;
				var _threshold = {
					targetId: threshold.targetId,
					thresholdType: threshold.thresholdType,
					thresholdParam: []
				};
				var thresholdParams = threshold.thresholdParam.filter(function(tsParam, i) {
					if (isBlank(tsParam.level_50) &&
						isBlank(tsParam.level_20) &&
						isBlank(tsParam.level_10) &&
						isBlank(tsParam.times)) {
						return false;
					} else {
						return true;
					}
				});
				thresholdParams.forEach(function(tsParam) {
					_threshold.thresholdParam.push({
						indicator: tsParam.indicator,
						operator: tsParam.operator,
						times: tsParam.times,
						level: {
							"50": tsParam.level_50,
							"20": tsParam.level_20,
							"10": tsParam.level_10
						}
					});
				});
				return _threshold;
			},

			_translateTradingToRemote: function(threshold) {
				var isBlank = Ember.isBlank;
				var _threshold = {
					targetId: threshold.targetId,
					thresholdType: threshold.thresholdType,
					thresholdParam: []
				};
				var thresholdParams = threshold.thresholdParam.filter(function(tsParam, i) {
					if (isBlank(tsParam.level_50) &&
						isBlank(tsParam.level_20) &&
						isBlank(tsParam.level_10) &&
						isBlank(tsParam.times)) {
						return false;
					} else {
						return true;
					}
				});
				thresholdParams.forEach(function(tsParam) {
					_threshold.thresholdParam.push({
						indicator: tsParam.indicator,
						operator: tsParam.operator,
						times: tsParam.times,
						level: {
							"50": tsParam.level_50,
							"20": tsParam.level_20,
							"10": tsParam.level_10
						}
					});
				});
				return _threshold;
			},

			actions: {
				ok: Ember.K,
				clear: Ember.K,
				cancel: Ember.K,
				saved: Ember.K
			}
		});

		return BusinessConfigThresholdComponent;
	}
);